﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StartWorkflow.aspx.cs"
    Inherits="ZX.WebApp.Crm.BasePages.StartWorkflow" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Src="~/Crm/BasePages/Affix1.ascx" TagName="Affix1" TagPrefix="uc1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <!--CSS file (default YUI Sam Skin) -->
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/paginator/assets/skins/sam/paginator.css" />
    <%--    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />--%>
    <!--begin custom header content for this example-->
    <style type="text/css">
        body
        {
            background-color: #FFFFFF;
            background: #ececec;

        }
    .yui-skin-sam table {
	    width: 100%;
    }
    
    #button-example-form fieldset, 
    #button-example-form fieldset div {

        border: 2px groove #ccc;
        margin: .5em;
        padding: .5em;

    }

    .yui-button#pushbutton2 button,
    .yui-button#pushbutton5 button, 
    .yui-button .Add button {
        background: url(../button/assets/add.gif) center center no-repeat;
        text-indent: -4em;
        overflow: hidden;
        padding: 0 .75em;
        width: 2em;
        *margin-left: 4em;   /* IE only */
        *padding: 0 1.75em;  /* IE only */

    }
    
    .yui-button#pushbutton3 button,
    .yui-button#pushbutton6 button, 
    .yui-button#pushbutton9 button {

        padding-left: 2em;
        background: url(../button/assets/add.gif) 10% 50% no-repeat;
    
    }
    #container select,#container input
    {
        width:100%;
        min-width:5em;
    }
    
    
    #toolbar
    {
        border-bottom:1px solid #ccc;
        margin-bottom:3px;
    }
    .form
    {
        padding:5px;
    }
    
    .form select
    {
        width:120px;
    }
    
    
        .style1
        {
            width: 52px;
        }
        .style2
        {
            width: 138px;
        }
        .style4
        {
            width: 36px;
        }
        .style5
        {
            width: 42px;
        }
    
    
        .style6
        {
            width: 208px;
        }
    
    
        .style7
        {
            width: 43px;
        }
    
    
    </style>
    <!--end custom header content for this example-->
    <!-- Dependencies -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <%--<script type="text/javascript" src="../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>--%>
    <!-- Source files -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery/DesignForm/DesignForm.Common.js" type="text/javascript"></script>
   
   <%-- <script src="Workflow.js" type="text/javascript"></script>--%>
   <script src="Workflow.js?v=1.0.0" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="contents" class="yui-skin-sam">
        <div style="border: 1px solid  #cccccc; float: left; clear: both; padding-right: 5px;
            padding-bottom: 5px; padding-top: 5px; line-height: 100px; width: 100%; height: 463px;">
            <table id="Center1">
                <tr>
                    <td>
                        <iframe class="EditUIWindow" id="EditUIWindow" frameborder="0" src="" style="width: 100%;
                            height: 100%; margin: 0px; padding: 0px;"></iframe>
                    </td>
                </tr>
               
                <tr>
                    <td style="background-color:#ececec;">
                        <div id="bottom1"  style=" float: right; margin-top: 10px; margin-right: 30px;">
                            <button type="button" id="btnCensorSubmit" name="btnCensorSubmit">

                                提交</button>
                             <button type="button" id="btnDraft" name="btnDraft" >
                            草稿</button>
                            <button type="button" id="btnClose" name="btnClose">
                                退出</button>
                          <%--<a href="Test.aspx">TEST</a>--%>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div style="display:none">
            <div id="dialog2" class="yui-pe-content">
                <div class="hd">
                    选择基本信息:</div>
                <div class="bd">
                    <iframe id="EditUIWindow1" frameborder="0" src="" style="width: 100%; height: 100%;
                        margin: 0px; padding: 0px;"></iframe>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var _WorkflowId = '<%=WorkFlowId %>',
           _WorktaskId = '<%=WorkTaskId %>',
           _TableName = '<%=TableName %>',
           _KeyValue = '<%=KeyValue %>',
        _FormType = '<%=FormType %>',
        _URL = '<% =URL %>',
        _StatusWorkflow='1',
        _IsIE = '<%=IsIE %>';
        (function () {

            //            var Dom = YAHOO.util.Dom,
            //            Event = YAHOO.util.Event;
            //            Event.onDOMReady(function () {
            //                var layout = new YAHOO.widget.Layout({
            //                    units: [
            //                { position: 'top', height: 35, body: 'toolbar', gutter: '1 1 1 1', scroll: null, zIndex: 2 },
            //                { position: 'center', body: 'EditUIWindow', gutter: '1 1', scroll: true },
            //                { position: 'bottom', body: 'Affixss', height: 45, gutter: '1 1', scroll: null, zIndex: 2}
            //                ]
            //                });
            //                layout.render();
            //            });
            if (_FormType == 'Html') {
                var load = function () {
                    //弹出对话框
                    YAHOO.namespace("example.container");

                    var handleSuccess = function (o) {
                        var response = o.responseText;
                        response = response.split("<!")[0];
                        document.getElementById("resp").innerHTML = response;
                    };
                    var handleCancel = function () {
                        this.cancel();
                    };
                    var handlePageCancel = function () {
                        /*this.cancel();
                        window.opener = null;
                        window.open("", "_self");
                        window.close();*/

                        window.parent.$("#tabs").tabs('close', '<% =PageTitle %>');
                    };
                    var handleFailure = function (o) {
                        alert("Submission failed: " + o.status);
                    };
                    var handleSubmit1 = function () {
                        var editwindow = document.getElementById("EditUIWindow1");
                        if (editwindow) {
                              if (_id == "btnProductLayoutID") {
                                if (editwindow.contentWindow.ids != "") {
                                    var _ProductLayoutID=editwindow.contentWindow.ids.replace(',','');
                                    
                                    //WF.init();
                                    WF.CrmProductLayout.init(_ProductLayoutID);
                                    var Begin = WF.CrmProductLayout.getBeginDate(); //开课日
                                    var End = WF.CrmProductLayout.getEndDate(); //结束日
                                    var Place = WF.CrmProductLayout.getPlace(); //地点


                                    $("#EditUIWindow").contents().find("#BeginDate").val(Begin); //开课日期
                                    $("#EditUIWindow").contents().find("#EndDate").val(End); // 结束日期
                                    $("#EditUIWindow").contents().find("#Place").val(Place); //地点
                                   // LoadTrainStudentInfo(editwindow.contentWindow.ids);
                                } else {
                                    alert("请选择一条记录!");
                                    return;
                                }
                            }
                            editwindow.contentWindow.ChooseInfo();
                        }
                        this.cancel();
                    };

                    YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2",
							    { width: "550px",
							        height: "450px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "保存", handler: handleSubmit1, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });

                    YAHOO.example.container.dialog2.render();
                    YAHOO.util.Event.onContentReady("bottom1", function () {
                        var btnCensorSubmit = new YAHOO.widget.Button("btnCensorSubmit");
                        btnCensorSubmit.on("click", handleSubmit);
                        var btnDraft= new YAHOO.widget.Button("btnDraft"); 
                        btnDraft.on("click",handleSubmitDraft);
                        var btnClose = new YAHOO.widget.Button("btnClose");
                        btnClose.on("click", handlePageCancel);

                    });

                };
                load();
                WF.init(_TableName, _WorkflowId, _WorktaskId);
                document.getElementById("EditUIWindow").src = _URL;
                document.getElementById("Affix").src = "Affix.aspx?WorkflowId=" + _WorkflowId + "&WorktaskId=" + _WorktaskId + "&WorkFlowInstanceId=" + "" + "&Status=0";
                $("#EditUIWindow").load(function () {
                    $(this).height($(this).contents().height());
                });
                $("#Affix").load(function () {
                    $(this).height($(this).contents().height());
                });

            } else { 
            
            window.location = _URL; 
            }


        })();


        function reinitIframe() {
            var iframe = document.getElementById("EditUIWindow");
            try {
                var bHeight = iframe.contentWindow.document.body.scrollHeight;
                var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
                var height = Math.max(bHeight, dHeight);
                iframe.height = height;
            } catch (ex) { }
        }

        var handleSubmit = function () {
            var editwindow = document.getElementById("EditUIWindow");
            if (editwindow) {

                setTimeout(function () {
                    var btn = document.getElementById("btnCensorSubmit");
                    _IsDraft = 0;
//                    var btns = document.getElementById("btnDraft");
//                    if (btns.value != null) {
//                        _IsDraft = 1;
//                    }
//                    btns.disabled = true;
                    btn.disabled = true;
                    editwindow.contentWindow.Save();
                    setTimeout(function () { btn.disabled = false }, 10000);
                }, 10);
            }
        };

        var handleSubmitDraft = function () {                           //todo zhuyun 20121019
            var editwindow = document.getElementById("EditUIWindow");
            if (editwindow) {
                setTimeout(function () {
                    var btn = document.getElementById("btnDraft");
                    _IsDraft = 1;
                    btn.disabled = true;
                    editwindow.contentWindow.Save();
                    setTimeout(function () { btn.disabled = false }, 1000000);
                }, 10);
            }
        };

        /* 对应的方法和ID*/
        var _fn, _id;
        function ShowDialog(fn, id, src) {
            //debugger;
            _fn = fn;
            _id = id;
            document.getElementById("EditUIWindow1").src = src;
            YAHOO.example.container.dialog2.show();
        }
        var _fn, _id;
        function ShowDialog1(fn, id, src) {
            _fn = fn;
            _id = id;
            document.getElementById("EditUIWindow1").src = src;
            YAHOO.example.container.dialog2.show();
        }
        /*刷新时候调用*/
        function closeWin() { }
 
        function ReLoadData(KeyValue, Title, Name, Value) {
            //debugger;
            if (typeof (KeyValue) == "undefined") { return; }
            if (typeof (Title) == "undefined") { Title = ''; }
            if (typeof (Value) == "undefined") { Value = ''; }

            if (typeof (_WorkflowId) != "undefined" && typeof (_WorktaskId) != "undefined" && typeof (_TableName) != "undefined" && typeof (KeyValue) != "undefined") {

                //不定期；

                if (Value != '')
                 {
                     WF.FreeFlow.init(_WorkflowId, _WorktaskId, Value, Name);
                    
                 }
                 if (WF.FreeFlow.getReturnValue() == '1') 
                 {

                     _IsDraft = '1';
                 }
               
                WF.setKeyvalue(KeyValue);
                WF.Start.init(Title, _IsDraft, Name, Value);
          

               
                //                $.ajax({
                //                    type: "POST",
                //                    url: "StartWorkflowData.aspx/WorkFlowStatr", //驱动流程起动
                //                    data: "{'TableName': '" + _TableName + "','KeyValue':'" + KeyValue + "','xWorkflowId':'" + _WorkflowId + "','xWorktaskId':'" + _WorktaskId + "'}",
                //                    contentType: "application/json; charset=utf-8",
                //                    dataType: "json",
                //                    success: function (data) {
                //                        
                //                        var resp = data.d;
                //                        if (resp.indexOf('OK%') >= 0) {
                //                            var respArray = resp.split("@");
                //                            if (respArray[0] == "OK%") {
                //                                //alert("成功");
                //                                //"tooltip.aspx?worktaskInstanceId=" + WorktaskInsId)
                //                                window.location = "tooltip.aspx?worktaskInstanceId=" + respArray[1];
                //                            } else {
                //                                alert("失败");
                //                            }
                //                        }
                //                        else {
                //                            alert("失败");
                //                        }
                //                    },
                //                    error: function (err) {
                //                        alert(err + "err");
                //                    }
                //                });
            }
        }

    </script>
    </form>
</body>
<%-- <script language="javascript" type="text/javascript">
     (function () {
         window.location = "<% =URL %>";

     })();
    </script>--%>
</html>
